package com.example.controller;

import com.example.domain.entity.Person;
import com.example.domain.query.PersonQuery;
import com.example.service.impl.PersonServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.service.IPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import java.util.List;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2025-05-12
 */
@RestController
@RequestMapping("/person")
public class PersonController {
    @Autowired
    private IPersonService personService;

    @GetMapping("/list")
    public List<Person> list() {
        return personService.list();
    }

    @PostMapping("/save")
    public boolean save(@RequestBody Person person) {
        return personService.save(person);
    }

    @PostMapping("/update")
    public boolean update(@RequestBody Person person) {
        return personService.updateById(person);
    }

    @DeleteMapping("/{id}")
    public void deleteById(@PathVariable int id) {
        if (!personService.removeById(id)) {
            throw new ResponseStatusException(HttpStatus.NOT_FOUND, "删除失败，人员不存在");
        }
    }
}
